package com.zhny.aiot.infrared.ray.plugin;

import com.zhny.aiot.infrared.ray.plugin.core.InfraredRayDevice;
import com.zhny.aiot.infrared.ray.plugin.model.InfraredRayStoreEntry;
import com.zhny.aiot.plugin.ICenterFacilities;
import com.zhny.aiot.plugin.IDevice;
import com.zhny.aiot.plugin.modbus.ModemServer;
import com.zhny.aiot.plugin.modbus.device.ModemConfig;
import com.zhny.aiot.plugin.modbus.device.ModemDeviceFactory;
import com.zhny.aiot.plugin.modbus.handler.model.ModemRequestMessage;
import com.zhny.aiot.plugin.model.DeviceEntity;
import com.zhny.aiot.plugin.model.FactoryType;
import com.zhny.aiot.plugin.model.StoreEntity;
import org.pf4j.Extension;
import org.pf4j.Plugin;
import org.pf4j.PluginWrapper;

import java.util.Calendar;
import java.util.Date;

public class InfraredRayPlugin extends Plugin {
    public InfraredRayPlugin(PluginWrapper wrapper) {
        super (wrapper);
    }
    @Extension
    public static class InfraredRay extends ModemDeviceFactory<InfraredRayStoreEntry> {

        public ModemRequestMessage getRequestMessage(ModemConfig modemConfig) {
            return new ModemRequestMessage (Integer.parseInt (modemConfig.getAddress ()),(short) 3,getDay(),7);
        }

        public IDevice createDevice(ICenterFacilities iCenterFacilities, DeviceEntity entity) {
            return new InfraredRayDevice(ModemServer.getInstance ().getEngine () ,this,iCenterFacilities,entity);
        }

        public Class<? extends StoreEntity> storeClass() {
            return InfraredRayStoreEntry.class;
        }

        public String getId() {
            return "zhny-infrared-ray-plugin";
        }

        public String getName() {
            return "智慧农业红外人体识别插件";
        }

        public FactoryType getType() {
            return FactoryType.Integrate;
        }

        private int getDay(){
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            int day = calendar.get(Calendar.DATE);
            return day;
        }
    }
}
